Skip to content

feat: Private gomod repo support#80

Merged
js-murph merged 15 commits intomainfrom
johnm/gomod-private-attempt-three
Feb 5, 2026
Merged

feat: Private gomod repo support#80
js-murph merged 15 commits intomainfrom
johnm/gomod-private-attempt-three

Conversation

@js-murph
Copy link
Copy Markdown
Contributor

@js-murph js-murph commented Feb 3, 2026

What?

Re-implements #77, which adds support for private gomod repositories.

Why?

So that we are able to cache private go modules.

Tests?

Includes new unit tests. Additionally some manual testing has been performed...

time curl http://localhost:8080/gomod/github.com/<org>/<repo>/@latest
{"Version":"v0.0.6","Time":"2021-08-12T18:29:12Z"}
real	1m43.818s
user	0m0.009s
sys	0m0.017s

time curl http://localhost:8080/gomod/github.com/<org>/<repo>/@latest
{"Version":"v0.0.6","Time":"2021-08-12T18:29:12Z"}
real	0m0.070s
user	0m0.006s
sys	0m0.011s

@js-murph js-murph requested a review from a team as a code owner February 3, 2026 08:45
@js-murph js-murph requested review from alecthomas and removed request for a team February 3, 2026 08:45
@js-murph js-murph marked this pull request as draft February 3, 2026 08:45
@js-murph js-murph marked this pull request as ready for review February 3, 2026 22:51
Copy link
Copy Markdown
Collaborator

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM if it works! :)

Comment on lines +18 to +33
var (
sharedManager *Manager
sharedManagerMu sync.RWMutex
)

func SetShared(m *Manager) {
sharedManagerMu.Lock()
defer sharedManagerMu.Unlock()
sharedManager = m
}

func GetShared() *Manager {
sharedManagerMu.RLock()
defer sharedManagerMu.RUnlock()
return sharedManager
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't tell why this exists. We should be constructing a single Manager in main, then passing it everywhere, so AFAICT we shouldn't need this?

Copy link
Copy Markdown
Contributor Author

@js-murph js-murph Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of where things load and where things need to be constructed, this gets more complicated than you might think. I'll address this as a separate PR because I think it might be easier to illustrate the problem and then we can work out what to do.

Comment thread internal/strategy/gomod/fetcher.go Outdated
Comment thread internal/strategy/gomod/gomod.go Outdated
Comment thread internal/strategy/gomod/matcher.go Outdated
Comment thread internal/strategy/gomod/private_fetcher.go Outdated
var output []byte
var err error

repo.WithReadLock(func() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also use generics here, so you can return values:

func WithRepoReadLock[R any](repo *Repository, apply func() (R, error)) (value R, err error) {
  repo.WithReadLock(func() { value, err = apply() })
  return
}

Usage:

output, err := gitclone.WithRepoReadLock(repo, func() ([]byte, error) {
		cmd := exec.CommandContext(ctx, "git", "-C", repo.Path(), "log", "-1", "--format=%cI", ref)
		return cmd.CombinedOutput()
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly clearer, but eh, your call

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might clean this up in a separate PR. Just because I think it's going to touch some additional code in the gitclone package.

Comment thread internal/strategy/gomod/private_fetcher.go Outdated
@js-murph js-murph merged commit 264021a into main Feb 5, 2026
5 checks passed
@js-murph js-murph deleted the johnm/gomod-private-attempt-three branch February 5, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants